//
//  BaseTableViewController.m
//  Education
//
//  Created by Davy on 2017/6/20.
//  Copyright © 2017年 Davy. All rights reserved.
//

#import "BaseTableViewController.h"

@interface BaseTableViewController ()



@end

@implementation BaseTableViewController

-(UIView *)emptyView{
    if (!_emptyView) {
        CGFloat h = 200;
        _emptyView = [[UIView alloc] initWithFrame:CGRectMake((DEVICE_SCREEN_WIDTH-h)/2, (DEVICE_SCREEN_HEIGHT-SafeAreaTopHeight-h)/2, h, h)];
        _emptyView.backgroundColor = [UIColor clearColor];
        
        _emptyImageView = [UIImageView new];
        _emptyImageView.contentMode = UIViewContentModeScaleAspectFit;
        _emptyImageView.image = [UIImage imageNamed:@"emptyData"];
        [_emptyView addSubview:_emptyImageView];
        [_emptyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(12);
            make.centerX.equalTo(_emptyView);
            make.width.height.mas_equalTo(120);
        }];
        
        _emptyLabel = [UILabel new];
        _emptyLabel.font = [UIFont systemFontOfSize:14];
        _emptyLabel.textColor = GRAYTEXTCOLOR;
        _emptyLabel.text = @"暂无数据";
        [_emptyView addSubview:_emptyLabel];
        [_emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.emptyImageView);
            make.top.equalTo(self.emptyImageView.mas_bottom).mas_offset(12);
        }];
    }
    return _emptyView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = BGCOLOR;
    
    self.tableView.separatorColor = SEPARATECOLOR;
    self.tableView.tableFooterView = [UIView new];
    
    NSArray *vcArray = [self.navigationController viewControllers];
    
    if (vcArray.count == 1) {
        
    }else{
        UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"return"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
        self.navigationItem.leftBarButtonItem = backBtn;
    }
}

-(void)addEmptyView{
    [self.view addSubview:self.emptyView];
}

-(void)removeEmptyView{
    [self.emptyView removeFromSuperview];
}

-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 弹出登录警告框
-(void)showLoginAction{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您的登录凭证已过期，请重新登录" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        LoginViewController *vc = [LoginViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }];
    [alert addAction:cancelAction];
    [alert addAction:confirmAction];
    [self presentViewController:alert animated:YES completion:nil];
}



- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleDefault;
    
}

@end
